import React, { Component } from 'react';
import {
	StyleSheet, Text, View, TouchableOpacity, PixelRatio
} from "react-native";
import { GLOBAL } from '../../../../../config/global';
import MethodUtil from '../../../../../utils/MethodUtil';
import { style } from '../../../../../theme/style';
import { CURRENCY } from '../../../../../utils/helper';

const scale = GLOBAL.SCALE;
export class PayApproveItem extends Component {
	constructor(props) {
		super(props);
	}

	render () {
		const { itemInfo, goDetail, approveType, choice } = this.props;
		const { paymentApplyInfo, taskId, taskName, formKey, auditResultName } = itemInfo;
		let { paymentApplyCode, createTime, paymentApplyAmount, paymentApplySource, paymentApplySourceName, staffName, bizTeamName, organName, companyName,
			applyItemList, currency, paymentApplyId } = paymentApplyInfo || {};
		return (
			<TouchableOpacity key={paymentApplyCode + paymentApplyId} activeOpacity={.5} style={styles.orderCell}
				onPress={() => {
					goDetail({
						paymentApplyId,
						taskId,
						dictKey: formKey,
						resUrl: 'PaymentApprovePage',
						auditResultName,
						paymentApplySource,
						approveType
					}, '付款审批')
				}}>
				<View style={styles.order}>
					<View style={styles.orderHeadView}>
						<View style={styles.orderHead}>
							<View style={styles.orderHeadLeft}>
								<Text style={styles.orderHeadText}>{paymentApplyCode || null}</Text>
								{/* <Image source={conPic} style={styles.conImage} /> */}
							</View>
							<Text style={styles.statusText}>{auditResultName}</Text>
						</View>
						<Text style={{ fontSize: 10 * scale, paddingBottom: 12 * scale, color: '#848A96' }}>(业务组织：{choice.corpName || '-'})</Text>
					</View>
					<View style={styles.orderMain}>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>供应商：</Text>
							<Text style={styles.orderVal}>
								{
									companyName ? (
										companyName.length > 8 ? (companyName.substr(0, 8) + '...') : companyName
									) : null
								}
							</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>任务名称：</Text>
							<Text style={styles.orderVal}>{taskName || ''}</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>申请来源：</Text>
							<Text style={styles.orderVal}>{paymentApplySourceName || ''}</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>付款单：</Text>
							<Text style={styles.orderVal}>{applyItemList ? applyItemList.length : 0}单</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>申请金额：</Text>
							<Text style={styles.orderVal}>{CURRENCY.getUnit(currency).label}{MethodUtil.toThousands(paymentApplyAmount, 2) || ''} {CURRENCY.getUnit(currency).text}</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>申请人：</Text>
							<Text style={styles.orderVal}>
								{staffName || ''}
							</Text>
						</View>
						<View style={styles.orderCol}>
							<Text style={styles.orderText}>申请时间：</Text>
							<Text style={styles.orderVal}>{createTime || ''}</Text>
						</View>
						<View style={styles.flexItem}>
							<Text style={styles.flexItemName}>业务员：</Text>
							<Text style={styles.flexItemTitle}>
								{staffName || '--'} | {bizTeamName || '--'} | {bizTeamName || '--'}
							</Text>
						</View>
					</View>
				</View>
			</TouchableOpacity>
		)
	}
}

const styles = StyleSheet.create({
	orderCell: {
		width: 375 * scale,
		backgroundColor: '#fff',
		alignItems: 'center',
		marginBottom: 12 * scale,
	},
	order: {
		width: 351 * scale,
	},
	orderHead: {
		width: 351 * scale,
		height: 44 * scale,
		justifyContent: 'space-between',
		alignItems: 'center',
		flexDirection: 'row',
	},
	orderHeadView: {
		width: 351 * scale,
		borderBottomColor: '#e4e4e4',
		borderBottomWidth: 1 / PixelRatio.get(),
	},
	orderHeadLeft: {
		height: 44 * scale,
		alignItems: 'center',
		flexDirection: 'row',
	},
	orderHeadText: {
		fontSize: 14 * scale,
		color: '#222',
		flexWrap: 'wrap'
	},
	statusText: {
		fontSize: 13 * scale,
		color: style.color.themeColor,
	},
	orderMain: {
		flexDirection: 'row',
		paddingTop: 8 * scale,
		paddingBottom: 8 * scale,
		flexWrap: 'wrap'
	},
	orderCol: {
		flexDirection: 'row',
		alignItems: 'center',
		height: 25 * scale,
		width: 175.5 * scale,
	},
	orderText: {
		fontSize: 12 * scale,
		color: '#8B8B8B'
	},
	orderVal: {
		fontSize: 12 * scale,
		color: '#000'
	},
	flexItem: {
		flexDirection: 'row',
	},
	flexItemName: {
		fontSize: 12 * scale,
		color: '#8B8B8B',
		paddingTop: 2 * scale,
	},
	flexItemTitle: {
		fontSize: 12 * scale,
		color: '#000',
		flexDirection: 'row',
		width: 298 * scale,
	},
})